import axiosServer from '../utils/request'
import type { IRole, IResponseData } from '@/utils/types'
/**
 * 登录接口
 * @param {*} username
 * @param {*} password
 * @returns
 */
export const RequestLogin = (username: string, password: string):Promise<IResponseData> => {
    return axiosServer({
        method: 'post',
        url: '/api/login',
        data: {
            username,
            password,
        },
    })
}

/**
 * get请求
 */
export const RequestDeleteProduct = (id: number):Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/shop/delete',
        params: {
            id,
        },
    })
}

/**
 * 验证码
 */
export const RequesetVeryCode = ():Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: 'api/verifyCode',
    })
}

/**
 * 动态菜单
 */
export const RequestMenu = (roleId: number):Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/system/menus',
        params: {
            roleId,
        },
    })
}
/**
 * 子菜单列表
 */
export const RequestSubMenu = (menuId: number):Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/system/submenu',
        params: {
            menuId,
        },
    })
}

/**
 * 添加菜单
 */
export const RequestMenuAdd = ({
    roleId,
    parentId,
    nodeType,
    menuName,
    path,
}) => {
    return axiosServer({
        method: 'post',
        url: '/api/system/addmenu',
        data: {
            roleId,
            parentId,
            nodeType,
            menuName,
            path,
        },
    })
}

/**
 * 角色列表
 */
export const RequestRoleList = (): Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/system/roles',
    })
}

/**
 * 添加角色
 */
export const RequestRoleAdd = (role: IRole):Promise<IResponseData> => {
    return axiosServer({
        method: 'post',
        url: '/api/system/addrole',
        data: {
            roleName: role.rolename,
            description: role.description,
        },
    })
}

/**
 * 编辑角色
 */
export const RequestRoleEdit = (role: IRole):Promise<IResponseData> => {
    return axiosServer({
        method: 'post',
        url: '/api/system/editrole',
        data: {
            roleId: role.r_id,
            roleName: role.rolename,
            description: role.description,
        },
    })
}

/**
 * 删除角色
 */
export const RequestRoleDelete = (roleId: number):Promise<IResponseData> => {
    return axiosServer({
        method: 'delete',
        url: '/api/system/deleterole',
        params: {
            roleId,
        },
    })
}

/**
 * 权限设置
 * ids:'1,3,4,5,6'
 * resType: 0菜单资源, 2按钮资源
 */
export const RequestAuthorRole = (
    roleId: number,
    ids: string,
    resType: number
) => {
    return axiosServer({
        method: 'put',
        url: '/api/system/author',
        params: {
            roleId,
            ids,
            resType,
        },
    })
}

/**
 * 账户列表
 * @returns
 */
export const RequestAccountList = (): Promise<IResponseData> => {
    return axiosServer({
        url: '/api/manager/list',
        method: 'get',
    })
}

/**
 * 注册-带头像上传
 */
export const RequestRegister = (formData: FormData): Promise<IResponseData> => {
    return axiosServer({
        method: 'post',
        url: '/api/register',
        headers: { 'Content-Type': 'multipart/form-data' },
        data: formData,
    })
}

/**
 * 删除账户
 */
export const RequestManagerDelete = (id: number): Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/manager/delete',
        params: {
            id,
        },
    })
}

/**
 * 资源权限
 */
export const RequestResource = (roleId:number):Promise<IResponseData> =>{
    return axiosServer({
        method:'get',
        url:'/api/system/resource',
        params:{
            roleId
        }
    })
}

/**
 * 修改用户
 * @param username 
 * @param nick 
 * @param roleId 
 * @returns 
 */
export const RequestAccountEdit = (data:any):Promise<IResponseData> => {
    return axiosServer({
        method: 'post',
        url: '/api/manager/update',
        data: {
            username:data.username,
            nick:data.nick,
            roleId:data.role_id,
        }
    })
}

/**
 * 日志列表
 * @param name 
 * @returns 
 */
export const RequestLog = (data:any):Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/log/list',
        params: {
            name: data.username,
            currentNo: data.currentNo,
            pageSize:data.pageSize
        }
    })
}


/**
 * 添加日志
 * @param data 
 * @returns 
 */
export const RequestAddLog = (data:any):Promise<IResponseData> => {
    return axiosServer({
        method: 'post',
        url: '/api/log/add',
        data: {
            mid: data.m_id,
            content: data.content,
            category: data.ctegory,
            logtime:data.logtime,
        }
    })
}

/**
 * 删除日志
 * @param data 
 * @returns 
 */
export const RequestDeleteLog = (data:any):Promise<IResponseData> => {
    return axiosServer({
        method: 'delete',
        url: '/api/log/delete',
        data: {
            id:data
        }
    })
}

/**
 * 检查操作员
 * @param username 
 * @returns 
 */
export const RequestManager = (username:any):Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url: '/api/manager/find',
        params: {
            username
        }
    })
}


/**
 * 商品列表分类
 * @returns 
 */
export const RequestShopList = ():Promise<IResponseData> => {
    return axiosServer({
        method: 'get',
        url:'/api/category'
    })
}